var util = require('../../utils/util.js');
var api = require('../../config/api.js');
// var user = require('../../utils/user.js');
// var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        orderInfo: {
            name: '阿里巴巴',
            mobile: '13292807157',
            orderStatus: '',
            orderStatusText: '',
            actualPrice: '',
            orderGoodsList: [],
            orderGoodsCount: '',
            orderGoodsPrice: '',
        },
        orderGoods: [],
        orderAll: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let params = decodeURIComponent(options.id || "");
        console.log(params, "params")

        console.log(util)
        console.log(api, "api")
        const that = this;
        util.request(api.GrouponOrder, {
            userId: params.split('/')[0],
            grouponId: params.split('/')[1],
        }).then(function (res) {
            console.log(res, "res")
            if (res.errno === 0) {
                that.setData({
                    orderInfo: res.data.orderInfo,
                    orderAll: res.data,
                    orderGoods: res.data.orderGoods
                });
            }
        });
    },

    confirm() {
        const that = this;
        wx.showModal({
            title: '提示',
            content: '确定要确认收货吗？',
            success: function (res) {
                if (res.confirm) {
                    util.request(api.GrouponOrderFinish, {
                        orderId: that.data.orderGoods[0].orderId
                    }, 'POST').then(function (res) {
                        if (res.errno === 0) {
                            wx.showToast({
                                title: '取货完成'
                            });
                            // wx.navigateBack({
                            //     delta: 1  // 返回上一个界面，如果要返回多个界面，可以增加 delta 的值
                            // });
                        }else{
                            util.showErrorToast(res.errmsg);
                        }
                    })
                }
            }
        })
    },
    continueHx() {
        const that = this;
        // 调取扫一扫
        wx.scanCode({
            success(res) {
                console.log(res)
                let params = res.result;
                util.request(api.GrouponOrder, {
                    userId: params.split('/')[0],
                    grouponId: params.split('/')[1],
                }).then(function (res) {
                    console.log(res, "res")
                    if (res.errno === 0) {
                        that.setData({
                            orderInfo: res.data.orderInfo,
                            orderAll: res.data,
                            orderGoods: res.data.orderGoods
                        });
                    }
                });
            }
        })
    }

})